from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import SKUImage, SKU
from meiduo_admin.serializers.images import SKUImageSerializer, SKUSerializer
from meiduo_admin.utils import PageNum


class ImageView(ModelViewSet):
    """
    图片表的增删改查
    """
    queryset = SKUImage.objects.all()
    serializer_class = SKUImageSerializer
    pagination_class = PageNum
    permission_classes = [IsAdminUser]


    # 自定义方法获取图片信息
    def simple(self,request):
        # 1.获取sku商品
        skus=SKU.objects.all()
        # 2.序列化返回sku商品
        ser=SKUSerializer(skus,many=True)
        return Response(ser.data)